package my.webservices.beans;

import static javax.persistence.CascadeType.ALL;

import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.NaturalId;

@Entity
@Table(name = "VEHICLE")
public class Vehicle extends BaseEntity{

	/**
	 * Serial version uid.
	 */
	private static final long serialVersionUID = 1762092284524377425L;

	/**
	 * Identifier.
	 */
	private Long id;

	/**
	 * Vehicle Id.
	 */
	private String vin;

	/**
	 * Vehicle's registered number.
	 */
	private String vehicleNumber;

	/**
	 * Vehicle's make.
	 */
	private Integer make;

	/**
	 * Vehicle's model.
	 */
	private String model;

	/**
	 * Vehicle's history.
	 */
	private Set<VehicleHistory> history;

	/**
	 * @return
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "VEH_ID")
	public Long getId() {
		return id;
	}

	/**
	 * @param id
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @return the vin
	 */
	@NaturalId(mutable = true)
	@Column(name = "VIN")
	public String getVin() {
		return vin;
	}

	/**
	 * @param vin
	 *            the vin to set
	 */
	public void setVin(String vin) {
		this.vin = vin;
	}

	/**
	 * @return the vehicleNumber
	 */
	@Column(name = "VEH_NUM")
	public String getVehicleNumber() {
		return vehicleNumber;
	}

	/**
	 * @param vehicleNumber
	 *            the vehicleNumber to set
	 */
	public void setVehicleNumber(String vehicleNumber) {
		this.vehicleNumber = vehicleNumber;
	}

	/**
	 * @return the make
	 */
	@Column(name = "VEH_MAKE", nullable = true)
	public Integer getMake() {
		return make;
	}

	/**
	 * @param make
	 *            the make to set
	 */
	public void setMake(Integer make) {
		this.make = make;
	}

	/**
	 * @return the model
	 */
	@Column(name = "VEH_MODEL", nullable = true)
	public String getModel() {
		return model;
	}

	/**
	 * @param model
	 *            the model to set
	 */
	public void setModel(String model) {
		this.model = model;
	}

	/**
	 * @return the history
	 */
	@OneToMany(mappedBy="id",cascade = ALL)
	public Set<VehicleHistory> getHistory() {
		return history;
	}

	/**
	 * @param history
	 *            the history to set
	 */
	public void setHistory(Set<VehicleHistory> history) {
		this.history = history;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((vin == null) ? 0 : vin.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Vehicle other = (Vehicle) obj;
		if (vin == null) {
			if (other.vin != null)
				return false;
		} else if (!vin.equals(other.vin))
			return false;
		return true;
	}

}
